Repository navigation
ENH: add vecdot and longdouble matmul - #124
Open
SwayamInSync wants to merge 14 commits into
Open
SwayamInSync wants to merge 14 commits into
SwayamInSync wants to merge 14 commits into
Conversation
…and dtype for vecdot
Member
Author
|
Requires #123 to be merged first to clear the CI issues here |
ngoldbaum
reviewed
Nov 24, 2026
| numpy_quaddtype.get_quadblas_version() | ||
| except NotImplementedError: | ||
| pytest.skip("without QuadBLAS the naive loop runs instead") | ||
| n = 2**23 |
Member
There was a problem hiding this comment.
rather than trying to make a multi-terabyte allocation, you can use resource.RLIMIT_AS to limit the address space of a subprocess and use a much smaller allocation:
import os
import resource
from pathlib import Path
import numpy as np
import pytest
from numpy_quaddtype import QuadPrecDType
dtype = QuadPrecDType()
n = 2048
a = np.broadcast_to(np.ones((), dtype=dtype), (n, n))
x = np.ones(n, dtype=dtype)
out = np.empty_like(x)
pages = int(Path("/proc/self/statm").read_text().split()[0])
limit = pages * os.sysconf("SC_PAGE_SIZE") + 8 * 1024**2
soft, hard = resource.getrlimit(resource.RLIMIT_AS)
if soft != resource.RLIM_INFINITY:
limit = min(limit, soft)
resource.setrlimit(resource.RLIMIT_AS, (limit, hard))
with pytest.raises(MemoryError):
np.matmul(a, x, out=out)I recently added a similar helper for memory limit tests like this in NumPy if you want more examples.
ngoldbaum
reviewed
Nov 24, 2026
ngoldbaum
left a comment
Member
There was a problem hiding this comment.
Just the one nitpick about the tests, otherwise this looks good to me.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
np.vecdotloop for both backends and makesnp.matmulwork for the longdouble backend, needed by NumPy's dot-family fallback for user DTypes.quad_dotinmatmul.cppis the shared dot-product path: QuadBLAS for aligned SLEEF operands with BLAS-compatible strides, otherwise a strided loop (SLEEFfma, or along doublesum).matmuluses the strided loop for the longdouble backend.vecdotloopsquad_dotover the outer dimensions;quad_add_dot_family_loopregisters it somatvec/vecmatcan reuse it.matmulused to segfault).tests/test_vecdot.py, longdouble and mixed-backendmatmultests, and an out-of-memory test.docs/api/functions.md.Known limitation, to handle after the release:
np.result_typepicks SLEEF for differing backends, while the ufuncs pick longdouble. NumPy'snp.dot/np.innerfallback casts tonp.result_typebefore callingmatmul, sonp.dotof a longdouble array with a float64 or SLEEF array returns a SLEEF result rounded through float64, whereasnp.matmulkeeps longdouble precision.